import 'package:flutter/material.dart';

class GenericGridItem<T> extends StatelessWidget {
  final T item;
  final Widget Function(T item) imageBuilder;
  final Widget Function(T item)? titleBuilder;
  final void Function(T item)? onTap;
  final double? imageWidth;
  final double? imageHeight;

  const GenericGridItem({
    super.key,
    required this.item,
    required this.imageBuilder,
    this.titleBuilder,
    this.onTap,
    this.imageWidth,
    this.imageHeight,
  });

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap != null ? () => onTap!(item) : null,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          ClipRRect(
            borderRadius: BorderRadius.circular(8),
            child: SizedBox(
              width: imageWidth,
              height: imageHeight,
              child: imageBuilder(item),
            ),
          ),
          const SizedBox(height: 4),
          if (titleBuilder != null)
            titleBuilder!(item)
          else
            const SizedBox.shrink(),
        ],
      ),
    );
  }
}
